Unreal Engine 4.25.4 您所在的位置:网站首页 ue4 createdefaultsubobject Unreal Engine 4.25.4

Unreal Engine 4.25.4

2023-04-12 15:52| 来源: 网络整理| 查看: 265

I have the following actor:

UCLASS() class X_API AMoveableRigidBodyActor : public AActor { GENERATED_BODY() public: // Sets default values for this actor's properties AMoveableRigidBodyActor(); public: UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Custom") USceneComponent* SceneComponent; UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Custom") UMoveableRigidBodyComponent* MoveableRigidBodyComponent; };

This Actor makes a reference to a UMoveableRigidBodyComponent and a USceneComponent which I run CreateDefaultSubobject on and attach in the following fashion in the constructor:

AMoveableRigidBodyActor::AMoveableRigidBodyActor() { SceneComponent = CreateDefaultSubobject(FName("AMoveableRigidBodyActor_SceneComponent")); SetRootComponent(SceneComponent); MoveableRigidBodyComponent = CreateDefaultSubobject(FName("AMoveableRigidBodyActor_MoveableRigidBodyComponent")); MoveableRigidBodyComponent->SetupAttachment(SceneComponent); }

So far, so good.

Now inside my UMoveableRigidBodyComponent I instantiate a few components that are relevant to that component. I expect these components to be visible and manageable from within my blueprint:

UCLASS() class X_API UMoveableRigidBodyComponent : public USceneComponent { GENERATED_BODY() public: // Sets default values for this component's properties UMoveableRigidBodyComponent(); override; UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Custom") USceneComponent* SceneComponent; UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Custom") UStaticMeshComponent* StaticMeshComponent; };

Here I use CreateDefaultSuboject to attach everything to this component:

UMoveableRigidBodyComponent::UMoveableRigidBodyComponent() { SceneComponent = CreateDefaultSubobject(FName("UMoveableRigidBodyComponent_SceneComponent")); SceneComponent->SetupAttachment(this); StaticMeshComponent = CreateDefaultSubobject(FName("UMoveableRigidBodyComponent_StaticMeshComponent")); StaticMeshComponent->SetupAttachment(SceneComponent); }

So, all of this feels pretty normal so far. So I go into my editor, create a blueprint that’s based off of the AMoveableRigidBodyActor and I assign a static mesh to my component:

324153-a.jpg 324153-a.jpg1606×979 243 KB

Still good. But then I hit the compile button:

324152-b.jpg 324152-b.jpg1605×977 245 KB

The selected static mesh has now vanished from the editor but still seems to be filling the value correctly.

Furthermore, if I put this into the game world you can see that the static mesh sure enough isn’t there in the instance:

324144-c.jpg 324144-c.jpg1280×786 198 KB

What am I misunderstanding here?



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有